/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		File Name		:		CPayer.h
//
//		Author			:		Kevin Jordan
//
//		Purpose			:		Encapsulate all functionality in the Player class
//
//		Dates			:		Written( Feb 15, 2011 ) by Kevin Jordan		LastUpdate( March 3, 2011  ) by Jayson Wu
//	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "CPlayer.h"
#include "MathLib.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "VIN_SoundManager.h"
#include "CPickup.h"
#include "CGame.h"
#include "CGamePlayState.h"
#include "CMeleeEnemy.h"
#include "CTestingLevelState.h"

enum PlayState{ Play_Idle= 0, Play_Walk, Play_Punch1,Play_Punch2,Play_Tackle,Play_Dead};
CPlayer::CPlayer()
{
	m_skDurability =0;
	m_skCombat = 0;
	m_skSpeed = 0;
	m_nRage = 0;
	m_bRagin = false;
	m_fOrigin = 0;
	m_bObjHeld = false;
	m_bJumped = false;
	m_bDoubleJump= false;
	CurAnimation = 0;

	Collection = 0;

	DuraPowered = false;
	ComabtPowered = false;
	SpeedPowered = false;
	RagePowered = false;

	m_fRageTime = 0.0f;
	m_fDuraTime = 0.0f;
	m_fCombatTime = 0.0f;
	m_fSpeedTime = 0.0f;

	m_nLives = 3;
	m_nHealth = 100;
	SetHP(m_nHealth);

	SetType(OBJ_PLAYER);
	flip = false;
	Load("resource/XML/Jack_Animation.xml");

	PlayerState = Play_Idle;
	leftpunch = false;
	rightpunch = true;

	bucket = 0;
	charge = 0;
	chargeTime = 0;
	Charging = false;
	vAnimation[CurAnimation].Play();
	flicker = true;
	flickbucket = 0;

}


CPlayer::~CPlayer()
{

}

void CPlayer::Render()
{
	CSGD_TextureManager* pTM  = CSGD_TextureManager::GetInstance();
	CSGD_Direct3D*		pD3D = CSGD_Direct3D::GetInstance();

	if(flicker)
		vAnimation[CurAnimation].Render(GetPosX(),GetPosY(),flip);



}
RECT CPlayer::GetAttackRect()
{
	RECT temp;
	if(CurAnimation < (int)vAnimation.size())
	{

		temp.left  = (int)GetPosX() + vAnimation[CurAnimation].GetAttackFrame().left ;
		temp.right = (int)GetPosX() + vAnimation[CurAnimation].GetAttackFrame().right;
		temp.top   = (int)GetPosY() + vAnimation[CurAnimation].GetAttackFrame().top;
		temp.bottom= (int)GetPosY() + vAnimation[CurAnimation].GetAttackFrame().bottom;
		if(flip)
		{
			temp.left = (int)GetPosX() - vAnimation[CurAnimation].GetAttackFrame().right ;
			temp.right =(int)GetPosX() - vAnimation[CurAnimation].GetAttackFrame().left;
		}
		return temp;
	}
	else
	{
		SetRect(&temp,0,0,0,0);
		return temp;
	}

}
RECT CPlayer::GetHealthRect()
{
	RECT temp;
	if(CurAnimation < (int)vAnimation.size())
	{
		temp.left  = (int)GetPosX() + vAnimation[CurAnimation].GetHealthFrame().left ;
		temp.right = (int)GetPosX() + vAnimation[CurAnimation].GetHealthFrame().right;
		temp.top   = (int)GetPosY() + vAnimation[CurAnimation].GetHealthFrame().top;
		temp.bottom= (int)GetPosY() + vAnimation[CurAnimation].GetHealthFrame().bottom;
		return temp;
	}
	else
	{
		SetRect(&temp,0,0,0,0);
		return temp;
	}


}

bool CPlayer::Input()
{

	if( GetRageAmt() == 100 )
	{
		if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_SPACE))
		{
			m_bRagin = true;
		}			
	}

	return true;
}


void CPlayer::Update(float fElapsedTime)
{
	SetVelX(0);
	SetVelY(0);

	if( m_bRagin && (GetRageAmt() != 0))
	{
		if( !RagePowered )
		{
			SetCombat( GetCombat() + 5 );
			SetSpeed( GetSpeed() + 5 );
			SetDurability( GetDurability() + 5 );
			RagePowered = true;
		}
		SetRageAmnt( GetRageAmt() - (75.0f * fElapsedTime)) ;
	}
	else if( GetRageAmt() <= 0 && m_bRagin)
	{
		m_bRagin = false;
		RagePowered = false;
		SetCombat( GetCombat() - 5 );
		SetSpeed( GetSpeed() - 5 );
		SetDurability( GetDurability() - 5 );
	}

	//Combat Settings

	if( GetCombat() == 0 )
	{
		CombatModifier = .5f;
	}
	else if( GetCombat() == 1 )
	{
		CombatModifier = 1.0f;
	}
	else if( GetCombat() == 2 )
	{
		CombatModifier = 1.5f;
	}
	else if( GetCombat() == 3 )
	{
		CombatModifier = 2.0f;
	}
	else if( GetCombat() == 4 )
	{
		CombatModifier = 2.5f;
	}
	else if( GetCombat() >= 5 )
	{
		CombatModifier = 3.0f;
	}


	//Speed Settings
	if( GetSpeed() == 0 )
	{
		SpeedModifier = .5f;
	}
	else if( GetSpeed() == 1 )
	{
		SpeedModifier = 1.0f;
	}
	else if( GetSpeed() == 2 )
	{
		SpeedModifier = 1.5f;
	}
	else if( GetSpeed() == 3 )
	{
		SpeedModifier = 2.0f;
	}
	else if( GetSpeed() == 4 )
	{
		SpeedModifier = 2.5f;
	}
	else if( GetSpeed() >= 5 )
	{
		SpeedModifier = 3.0f;
	}

	//Rage Settings
	if( GetRage() == 0 )
	{
		RageModifier = .5f;
	}
	else if( GetRage() == 1 )
	{
		RageModifier = 1.0f;
	}
	else if( GetRage() == 2 )
	{
		RageModifier = 1.5f;
	}
	else if( GetRage() == 3 )
	{
		RageModifier = 2.0f;
	}
	else if( GetRage() == 4 )
	{
		RageModifier = 2.5f;
	}
	else if( GetRage() >= 5 )
	{
		RageModifier = 3.0f;
	}

	//Durability
	if( GetDurability() == 0 )
	{
		DurabilityModifier = .5f;
	}
	else if( GetDurability() == 1 )
	{
		DurabilityModifier = 1.0f;
	}
	else if( GetDurability() == 2 )
	{
		DurabilityModifier = 1.5f;
	}
	else if( GetDurability() == 3 )
	{
		DurabilityModifier = 2.0f;
	}
	else if( GetDurability() == 4 )
	{
		DurabilityModifier = 2.5f;
	}
	else if( GetDurability() >= 5 )
	{
		DurabilityModifier = 3.0f;
	}





	if( CGamePlayState::GetInstance()->GetGameStatus() )
	{
		switch(PlayerState)
		{
		case Play_Idle:
			{
				//What do i do while in here'
				//SetVelX(0);
				//State Transitions
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_X) ||  CSGD_DirectInput::GetInstance()->JoystickButtonPressed(0))
				{
					if(rightpunch == true)
					{
						rightpunch = false;
						ChangeState(Play_Punch1);
					}
					else if(rightpunch == false)
					{
						rightpunch = true;
						ChangeState(Play_Punch2);
					}
					VIN_SoundManager::GetInstance()->PlayWoosh();
				}
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_C))
				{
					ChangeState(Play_Tackle);
				}
				if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_RIGHT) ||  CSGD_DirectInput::GetInstance()->JoystickGetLStickDirDown(DIR_RIGHT))
				{
					if(flip == true)
						flip = false;
					ChangeState(Play_Walk);
				}
				else if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_LEFT) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirDown(DIR_LEFT))
				{
					if(flip == false)
						flip = true;
					ChangeState(Play_Walk);
				}
				else if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_UP) || CSGD_DirectInput::GetInstance()->KeyDown(DIK_DOWN) )
				{
					ChangeState(Play_Walk);
				}




			}
			break;
		case Play_Walk:
			{
				//Movement Left and Right
				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_C))
				{
					ChangeState(Play_Tackle);
				}
				if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_RIGHT) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirDown(DIR_RIGHT))
				{
					SetVelX(100 * SpeedModifier );
					SetPosX(GetPosX() + GetVelX() * CGame::GetInstance()->GetElapsedTime());
				}
				else if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_LEFT) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirDown(DIR_LEFT))
				{
					SetVelX(-100 * SpeedModifier);
					SetPosX(GetPosX() + GetVelX() * CGame::GetInstance()->GetElapsedTime());
				}


				if( CSGD_DirectInput::GetInstance()->KeyDown(DIK_UP) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirDown(DIR_UP))
				{
					SetVelY(-100 * SpeedModifier);
					SetPosY( GetPosY() + GetVelY() * CGame::GetInstance()->GetElapsedTime());
				}
				else if( CSGD_DirectInput::GetInstance()->KeyDown(DIK_DOWN) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirDown(DIR_DOWN) )
				{
					SetVelY(100 * SpeedModifier);
					SetPosY( GetPosY() + GetVelY() * CGame::GetInstance()->GetElapsedTime() );
				}

				if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_X) || CSGD_DirectInput::GetInstance()->JoystickButtonPressed(0) )
				{
					if(rightpunch == true)
					{
						rightpunch = false;
						ChangeState(Play_Punch1);
					}
					else if(rightpunch == false)
					{
						rightpunch = true;
						ChangeState(Play_Punch2);
					}
				}

				//State Transitions
				if(GetVelX() == 0 && GetVelY() == 0)
				{
					ChangeState(Play_Idle);
				}
				break;
		case Play_Punch1:
			{
				//what to do while in here
				//State Transitions
				if(vAnimation[CurAnimation].GetCurFrame() >= vAnimation[CurAnimation].GetMaxFrames() -1)
				{
					if(vAnimation[CurAnimation].Playing())
					{
						vAnimation[CurAnimation].Stop();
						vAnimation[CurAnimation].Reset();
					}
					ChangeState(Play_Idle);
				}
			}
			break;
		case Play_Punch2:
			{
				//what to do while in here
				//State Transitions
				if(vAnimation[CurAnimation].GetCurFrame() >= vAnimation[CurAnimation].GetMaxFrames() -1)
				{
					if(vAnimation[CurAnimation].Playing())
					{
						vAnimation[CurAnimation].Stop();
						vAnimation[CurAnimation].Reset();
					}
					ChangeState(Play_Idle);
				}
			}
			break;
		case Play_Tackle:
			{
				if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_C))
				{
					Charging = true;
					charge = 500;
					if(flip)
						SetVelX(-charge);
					else
						SetVelX(charge);
				}

			}
			break;
		case Play_Dead:
			{
				if(vAnimation[CurAnimation].GetCurFrame() >= vAnimation[CurAnimation].GetMaxFrames() -1)
				{
					if(vAnimation[CurAnimation].Playing())
						vAnimation[CurAnimation].Stop();
					if(GetLives() >= 0)
					{
						bucket += fElapsedTime;
						flickbucket += fElapsedTime;
						if(flickbucket > .12f)
						{
							flicker = !flicker;
							flickbucket = 0;
						}
						if(bucket >= 1.0f)
						{
							bucket = 0;
							SetLives(GetLives() - 1);
							ResetPlayer();
							vAnimation[CurAnimation].Reset();
							ChangeState(0);
							flicker = true;
						}
					}
					else
					{
						CGamePlayState::GetInstance()->GameOver(true);
						CGamePlayState::GetInstance()->CalculateScore( CTestingLevelState::GetInstance()->GetWaveCount(), CHubState::GetInstance()->GetPlayer()->GetCash(), (int)CTestingLevelState::GetInstance()->GetWaveTime(),  (int)CHubState::GetInstance()->GetPlayer()->GetRageAmt(),  (int)CHubState::GetInstance()->GetPlayer()->GetHP());
					}
				}
			}
			break;
			};


		}


	}
	if(GetHP() <= 0 )
	{
		ChangeState(5);
	}
	if(Charging)
		chargeTime += fElapsedTime;
	if(chargeTime > 0.5f)
	{
		charge = 0;
		chargeTime = 0;
		SetVelX(0);
		Charging = false;
		ChangeState(Play_Idle);
	}
	CBaseObject::Update( fElapsedTime );

	vAnimation[CurAnimation].Update(fElapsedTime);
	vAnimation[CurAnimation].Play();
	//// Apply gravity to the player
	//SetVelY( GetVelY() + 500 * fElapsedTime );

	// Temporary check to keep player on the ground
	/*if( GetPosY() > 500  )
	{
	SetPosY(500);
	SetVelY(0);
	Jumpy();
	}*/

	/*if( IsPissed() )
	{
		m_fRageTime += fElapsedTime;
		if( m_fRageTime >= 10.0f )
		{
			m_bRagin = false;
		}
	}*/

	if( IsDurable() )
	{
		m_fDuraTime += fElapsedTime;
		if( m_fDuraTime >= 10.0f )
		{
			DuraPowered = false;
		}
	}

	if( IsFast() )
	{
		m_fSpeedTime += fElapsedTime;
		if( m_fSpeedTime >= 10.0f )
		{
			SpeedPowered = false;
		}
	}

	if( IsDeadly() )
	{
		m_fCombatTime += fElapsedTime;
		if( m_fCombatTime >= 10.0f )
		{
			ComabtPowered = false;
			SetCombat(GetCombat() - 5 );
		}
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////


	if( GetPosY() <= 450 )
		SetPosY(450);

	else if( GetPosY() > 600)
		SetPosY(600);

	if( GetPosX() < 0 )
		SetPosX(0);
	else if( (GetPosX() + GetWidth() + 25) > CSGD_Direct3D::GetInstance()->GetPresentParams()->BackBufferWidth )
		SetPosX( (float)CSGD_Direct3D::GetInstance()->GetPresentParams()->BackBufferWidth - GetWidth() - 25 );

}

bool CPlayer::CheckCollision( IBaseInterface* pBase )
{
	RECT TempRect;

	if(pBase->GetType() == OBJ_ENEMY)
	{

		CMeleeEnemy* enemy = (CMeleeEnemy*)pBase;
		if( IntersectRect(&TempRect, &GetAttackRect(),&enemy->GetHealthRect()) )
		{
			VIN_SoundManager::GetInstance()->PlayPunch();
			enemy->HurtMe();
			if(!m_bRagin)
				SetRageAmnt(GetRageAmt() + 1.0f );
			if( enemy->GetHP() <= 0 )
			{
				CTestingLevelState::GetInstance()->IncrementDead();
				
			}
		}
	}

	if( pBase->GetType() == OBJ_PICK )
	{	
		CPickup* pPBase = (CPickup*)pBase;

		if(IntersectRect(&TempRect, &GetHealthRect(), &pBase->GetRect() ) )
		{
			if(CSGD_DirectInput::GetInstance()->KeyDown(DIK_X))
			{
				if(!m_bObjHeld)
				{
					m_bObjHeld = true;
					HeldObject = pPBase;
				}
			}
			if(CSGD_DirectInput::GetInstance()->KeyReleased(DIK_X))
			{
				if(pPBase->GetPickupType() == PICK_PLAT)
				{
					m_bObjHeld = false;
					Throw(pPBase);
					HeldObject = NULL;
				}
			}

			/*if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_Z) || CSGD_DirectInput::GetInstance()->JoystickButtonPressed(1) )
			{
				if(pPBase->GetPickupType() == PICK_NORMAL)
				{
					m_bObjHeld = false;
					Throw(pPBase);
					HeldObject = NULL;
				}
			}*/
		}

		if(m_bObjHeld == true)
		{
			if(HeldObject != NULL && HeldObject == pPBase)
			{
				if(pPBase->GetPickupType() ==  PICK_PLAT)
				{
					pPBase->SetPosY(GetPosY() - pPBase->GetHeight() + 1);
					pPBase->SetPosX(GetPosX() + 1);
					// Make player hold above head animation
				}
				if(pPBase->GetPickupType() == PICK_NORMAL)
				{
					if(GetVelX() < 0)
						pPBase->SetPosX(GetPosX() - pPBase->GetWidth() + 1);
					// Make Player hold at Weapon Point

					else if(GetVelX() > 0)
						pPBase->SetPosX(GetPosX() + GetWidth() - 1);
					// Make Player hold at Weapon Point
					pPBase->SetPosY(GetPosY() + (GetHeight()/2));
				}
				pPBase->SetVelY(0);
			}
		}
	}
	return false;
}


bool CPlayer::Load( const char* AnimInfo)
{
	int tempID;

	TiXmlDocument doc;

	if(doc.LoadFile(AnimInfo) == false)
		return false;

	TiXmlElement* Root = doc.RootElement();
	if(Root == NULL)
		return false;

	TiXmlElement* NumAnim = Root->FirstChildElement("xNumOfAnim");
	int count = atoi(NumAnim->GetText());

	TiXmlElement* ImageFile = Root->FirstChildElement("xImageFile");
	if(ImageFile)
	{
		tempID = CSGD_TextureManager::GetInstance()->LoadTexture(ImageFile->GetText());
	}

	TiXmlElement* xAnimation  = Root->FirstChildElement("xAnimation");

	while(xAnimation)
	{
		CAnimation a;

		TiXmlElement* NumFrame = xAnimation->FirstChildElement("xNumOfFrames");
		int fcount = atoi(NumFrame->GetText());

		TiXmlElement* looping = xAnimation->FirstChildElement("xLooping");
		a.SetIsLooping((bool)(atoi(looping->GetText())));

		TiXmlElement* AnimSpd = xAnimation->FirstChildElement("xAnimSpd");
		a.SetSpeed((float)( atoi(AnimSpd->GetText())));

		TiXmlElement* xFrame = xAnimation->FirstChildElement("xFrame");

		Frame temp;
		temp.fTime = 0;
		temp.ptAnchor.x = 0;
		temp.ptAnchor.y = 0;

		SetRect(&temp.rAttack,0,0,0,0);
		SetRect(&temp.rCollision,0,0,0,0);
		SetRect(&temp.rRender,0,0,0,0);

		temp.ptAnchor.x = 0;
		temp.ptAnchor.y = 0;

		while(xFrame)
		{
			TiXmlElement* xTime = xFrame->FirstChildElement("xTime");
			if(xTime)
			{
				temp.fTime =(float)( atoi(xTime->GetText()) );
			}
			TiXmlElement* FrameType = xFrame->FirstChildElement("xFrameType");
			if(FrameType)
			{
				TiXmlElement* RenderFrame = FrameType->FirstChildElement("xRenderFrame");
				if(RenderFrame)
				{
					TiXmlElement* RenderFrameX = RenderFrame->FirstChildElement("xRenderFrameX");
					if(RenderFrameX)
						temp.rRender.left =  atoi(RenderFrameX->GetText());

					TiXmlElement* RenderFrameY = RenderFrame->FirstChildElement("xRenderFrameY");
					if(RenderFrameY)
						temp.rRender.top = atoi(RenderFrameY->GetText());

					TiXmlElement* RenderFrameW = RenderFrame->FirstChildElement("xRenderFrameW");
					if(RenderFrameW)
					{
						temp.rRender.right = atoi(RenderFrameW->GetText());
						temp.rRender.right += temp.rRender.left;
					}
					TiXmlElement* RenderFrameH = RenderFrame->FirstChildElement("xRenderFrameH");
					if(RenderFrameH)
					{
						temp.rRender.bottom = atoi(RenderFrameH->GetText());
						temp.rRender.bottom += temp.rRender.top;
					}
				}

				TiXmlElement* CollisionFrame = FrameType->FirstChildElement("xCollisionFrame");
				if(CollisionFrame)
				{
					TiXmlElement* CollisionFrameX = CollisionFrame->FirstChildElement("xCollisionFrameX");
					if(CollisionFrameX)
						temp.rCollision.left = atoi(CollisionFrameX->GetText());

					TiXmlElement* CollisionFrameY = CollisionFrame->FirstChildElement("xCollisionFrameY");
					if(CollisionFrameY)
						temp.rCollision.top = atoi(CollisionFrameY->GetText());

					TiXmlElement* CollisionFrameW = CollisionFrame->FirstChildElement("xCollisionFrameW");
					if(CollisionFrameW)
						temp.rCollision.right = atoi(CollisionFrameW->GetText());

					TiXmlElement* CollisionFrameH = CollisionFrame->FirstChildElement("xCollsionFrameH");
					if(CollisionFrameH)
						temp.rCollision.bottom = atoi(CollisionFrameH->GetText());
				}

				TiXmlElement* AttackFrame = FrameType->FirstChildElement("xAttackFrame");
				if(AttackFrame)
				{
					TiXmlElement* AttackFrameX = AttackFrame->FirstChildElement("xAttackFrameX");
					if(AttackFrameX)
						temp.rAttack.left = atoi(AttackFrameX->GetText());

					TiXmlElement* AttackFrameY = AttackFrame->FirstChildElement("xAttackFrameY");
					if(AttackFrameY)
						temp.rAttack.top = atoi(AttackFrameY->GetText());

					TiXmlElement* AttackFrameW = AttackFrame->FirstChildElement("xAttackFrameW");
					if(AttackFrameW)
						temp.rAttack.right = atoi(AttackFrameW->GetText());

					TiXmlElement* AttackFrameH = AttackFrame->FirstChildElement("xAttackFrameH");
					if(AttackFrameH)
						temp.rAttack.bottom = atoi(AttackFrameH->GetText());
				}

				TiXmlElement* AnchorPoint = FrameType->FirstChildElement("xAnchorPoint");
				if(AnchorPoint)
				{
					TiXmlElement* AnchorPointX = AnchorPoint->FirstChildElement("xAnchorPointX");
					if(AnchorPointX)
					{
						int ax = atoi(AnchorPointX->GetText());
						temp.ptAnchor.x =  ax - temp.rRender.left;
					}

					TiXmlElement* AnchorPointY = AnchorPoint->FirstChildElement("xAnchorPointY");
					if(AnchorPointY)
					{
						int ay = atoi(AnchorPointY->GetText());
						temp.ptAnchor.y = ay - temp.rRender.top;
					}
				}
			}
			a.SetTimeDelay(temp.fTime);

			temp.rAttack.right +=  temp.rAttack.left;
			temp.rAttack.bottom += temp.rAttack.top;
			temp.rAttack.left -= (temp.ptAnchor.x + temp.rRender.left);
			temp.rAttack.top -= (temp.ptAnchor.y + temp.rRender.top);
			temp.rAttack.right -= (temp.ptAnchor.x + temp.rRender.left);
			temp.rAttack.bottom -=(temp.ptAnchor.y + temp.rRender.top);



			temp.rCollision.right +=  temp.rCollision.left;
			temp.rCollision.bottom += temp.rCollision.top;
			temp.rCollision.left -= (temp.ptAnchor.x + temp.rRender.left);
			temp.rCollision.top -= (temp.ptAnchor.y + temp.rRender.top);
			temp.rCollision.right -= (temp.ptAnchor.x + temp.rRender.left);
			temp.rCollision.bottom -=(temp.ptAnchor.y + temp.rRender.top);


			a.addFrame(temp);
			xFrame = xFrame->NextSiblingElement("xFrame");
		}
		a.SetImageID(tempID);
		vAnimation.push_back(a);

		xAnimation = xAnimation->NextSiblingElement("xAnimation");
	}

	return true;
}
void CPlayer::Throw(IBaseInterface* ThrownObj)
{
	if(ThrownObj->GetType() == OBJ_PICK)
	{
		CPickup* TrowIt = (CPickup*)ThrownObj;
		TrowIt->SetVelY(GetVelY() + 30);
		TrowIt->SetVelX(GetVelX() * 3);
	}
}

void CPlayer::OnEnter(int newState)
{
	switch(PlayerState)
	{
	case Play_Idle:
		{
			SetCurAnimation(0);
		}
		break;
	case Play_Walk:
		{
			SetCurAnimation(1);
		}
		break;
	case Play_Punch1:
		{
			SetCurAnimation(2);
		}
		break;
	case Play_Punch2:
		{
			SetCurAnimation(3);
		}
		break;
	case Play_Tackle:
		{
			SetCurAnimation(1);
		}
		break;
	case Play_Dead:
		{
			SetCurAnimation(4);
		}
	};
}
void CPlayer::ChangeState(int newState)
{
	PlayerState = newState;
	OnEnter(newState);
}

void CPlayer::ResetPlayer()
{
	//CALLED AT THE END OF A LEVEL WHENEVER EXITING
	SetPosX(360);
	SetPosY(400);

	DuraPowered = false;
	ComabtPowered = false;
	SpeedPowered = false;
	RagePowered = false;

	m_fRageTime = 0.0f;
	m_fDuraTime = 0.0f;
	m_fCombatTime = 0.0f;
	m_fSpeedTime = 0.0f;

	SetHP(m_nHealth);
	flip = false;

	PlayerState = Play_Idle;
	leftpunch = false;
	rightpunch = true;
}
